package main.rabbitmqProvider.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DirectModeConfig {
    public static final String DIRECT_EXCHANGE_NAME = "direct_exchange";

    //创建交换机
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange(DIRECT_EXCHANGE_NAME);
    }

    //创建队列
    @Bean
    public Queue directQueue1() {
        return new Queue("direct_queue1");
    }

    @Bean
    public Queue directQueue2() {
        return new Queue("direct_queue2");
    }

    @Bean
    public Queue directQueue3() {
        return new Queue("direct_queue3");
    }

    //绑定队列和交换机
    @Bean
    public Binding bindingDirectQueue1() {
        return BindingBuilder.bind(directQueue1()).to(directExchange()).with("direct_routing_key1");
    }

    @Bean
    public Binding bindingDirectQueue2() {
        return BindingBuilder.bind(directQueue2()).to(directExchange()).with("direct_routing_key2");
    }

    @Bean
    public Binding bindingDirectQueue3() {
        return BindingBuilder.bind(directQueue3()).to(directExchange()).with("direct_routing_key3");
    }
}
